package com.zb.article.controller;

import com.zb.article.service.AuthorService;
import com.zb.model.common.Result;
import com.zb.model.pojo.article.ApAuthor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/author")
public class AuthorController{
    @Autowired
    private AuthorService authorService;
//    根据appUserId查询关联作者信息
    @GetMapping("/findByUserId/{userId}")
    public Result<ApAuthor> findByUserId(@PathVariable("userId") Integer userId) {
        return Result.SUCCESS(authorService.findByUserId(userId));
    }
//    保存作者信息
    @PostMapping("/save")
    public Result save(@RequestBody ApAuthor apAuthor) {
        Integer authorId = authorService.save(apAuthor);
        if(authorId != null) {
            return Result.SUCCESS(authorId);
        }else {
            return Result.FAIL();
        }
    }
}
